home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cvs / sprite / build_entry.c < prev    next >
C/C++ Source or Header  |  1991-07-29  |  3KB  |  90 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Id: build_entry.c,v 1.2 91/07/29 11:53:37 jhh Exp $";
  3. #endif !lint
  4.  
  5. /*
  6.  *    Copyright (c) 1989, Brian Berliner
  7.  *
  8.  *    You may distribute under the terms of the GNU General Public License
  9.  *    as specified in the README file that comes with the CVS 1.0 kit.
  10.  *
  11.  * Build Entry
  12.  *
  13.  *    Builds an entry for a new file and sets up "CVS.adm/file",[pt] by
  14.  *    interrogating the user.
  15.  *
  16.  *    Returns non-zero on error.
  17.  */
  18.  
  19. #include <sys/param.h>
  20. #include "cvs.h"
  21.  
  22. Build_Entry(message)
  23.     char *message;
  24. {
  25.     char fname[MAXPATHLEN];
  26.     char line[MAXLINELEN];
  27.     FILE *fp, *fptty;
  28.  
  29.     /*
  30.      * There may be an old file with the same name in the Attic!
  31.      * This is, perhaps, an awkward place to check for this, but
  32.      * other places are equally awkward.
  33.      */
  34.     (void) sprintf(fname, "%s/%s/%s%s", Repository, CVSATTIC, User, RCSEXT);
  35.     if (isreadable(fname)) {
  36.     warn(0, "there is an old file %s already in %s/%s", User,
  37.          Repository, CVSATTIC);
  38.     return (1);
  39.     }
  40.     /*
  41.      * The options for the "add" command are store in the file CVS.adm/User,p
  42.      */
  43.     (void) sprintf(fname, "%s/%s%s", CVSADM, User, CVSEXT_OPT);
  44.     fp = open_file(fname, "w+");
  45.     if (fprintf(fp, "%s\n", Options) == EOF)
  46.     error(1, "cannot write %s", fname);
  47.     (void) fclose(fp);
  48.     /*
  49.      * And the requested log is read directly from the user and stored
  50.      * in the file User,t.  If the "message" argument is set, then the
  51.      * user specified the -m option to add, and it is not necessary to
  52.      * query him from the terminal.
  53.      */
  54.     (void) sprintf(fname, "%s/%s%s", CVSADM, User, CVSEXT_LOG);
  55.     fp = open_file(fname, "w+");
  56.     if (message[0] == '\0') {
  57.     printf("RCS file: %s\n", Rcs);
  58.     printf("enter description, terminated with ^D or '.':\n");
  59.     printf("NOTE: This is NOT the log message!\n");
  60. #ifdef sprite
  61.     fptty = open_file(getenv("TTY"), "r");
  62. #else
  63.     fptty = open_file("/dev/tty", "r");
  64. #endif
  65.     for (;;) {
  66.         printf(">> ");
  67.         (void) fflush(stdout);
  68.         if (fgets(line, sizeof(line), fptty) == NULL ||
  69.         (line[0] == '.' && line[1] == '\n'))
  70.         break;
  71.         if (fputs(line, fp) == EOF)
  72.         error(1, "cannot write to %s", fname);
  73.     }
  74.     printf("done\n");
  75.     (void) fclose(fptty);
  76.     } else {
  77.     if (fputs(message, fp) == EOF)
  78.         error(1, "cannot write to %s", fname);
  79.     }
  80.     (void) fclose(fp);
  81.     /*
  82.      * Create the entry now, since this allows the user to interrupt
  83.      * us above without needing to clean anything up (well, we could
  84.      * clean up the ,p and ,t files, but who cares).
  85.      */
  86.     (void) sprintf(line, "Initial %s", User);
  87.     Register(User, "0", line);
  88.     return (0);
  89. }
  90.